Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unist-util-filter

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-filter

Create a new Unist tree with all nodes that pass the test implemented by the provided function

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
365K
increased by5.42%
Maintainers
2
Weekly downloads
 
Created

What is unist-util-filter?

The `unist-util-filter` package is a utility for filtering nodes in a Unist syntax tree. It allows you to traverse and selectively remove nodes based on a predicate function, making it useful for tasks such as cleaning up or transforming abstract syntax trees (ASTs).

What are unist-util-filter's main functionalities?

Filter nodes based on a predicate

This feature allows you to filter nodes in a Unist tree based on a predicate function. In this example, the tree is filtered to remove paragraphs containing the text 'World'.

const filter = require('unist-util-filter');
const tree = {
  type: 'root',
  children: [
    { type: 'paragraph', children: [{ type: 'text', value: 'Hello' }] },
    { type: 'paragraph', children: [{ type: 'text', value: 'World' }] }
  ]
};
const filteredTree = filter(tree, node => node.type !== 'paragraph' || node.children[0].value !== 'World');
console.log(filteredTree);

Filter nodes with a specific type

This feature allows you to filter out nodes of a specific type. In this example, all 'heading' nodes are removed from the tree.

const filter = require('unist-util-filter');
const tree = {
  type: 'root',
  children: [
    { type: 'paragraph', children: [{ type: 'text', value: 'Hello' }] },
    { type: 'heading', children: [{ type: 'text', value: 'Title' }] }
  ]
};
const filteredTree = filter(tree, node => node.type !== 'heading');
console.log(filteredTree);

Other packages similar to unist-util-filter

Keywords

FAQs

Package last updated on 31 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc